define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'member/addrelusr/index' + location.search,
                    add_url: 'member/addrelusr/add',
                  //  edit_url: 'member/addrelusr/edit',
                    del_url: 'member/addrelusr/del',
                  //  multi_url: 'member/addrelusr/multi',
                   // import_url: 'member/addrelusr/import',
                    table: 'address_list',
                }
            });

            var table = $("#table");


            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                // console.log(data);
                //这里我们手动设置底部的值
                $("#total_usr").text(data.extend.total_usr);
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        // {checkbox: true},
                        {field:'no',title:__('序号'),operate:false,
                            formatter:function(value,row,index){
                                var pageSize=table.bootstrapTable('getOptions').pageSize;//获取每页显示的数量
                                var pageNumber=table.bootstrapTable('getOptions').pageNumber;//获取当前是第几面
                                return pageSize * (pageNumber - 1) + index +1 ;
                            }
                        },
                        {field: 'account.username', title: __('Account.username'), operate: 'LIKE'},
                        {field: 'account.nickname', title: __('Account.nickname'), operate: 'LIKE'},
                        {field: 'account.mobile', title: __('Account.mobile')},
                        {field: 'isparty', title: __('Isparty')},
                        {field: 'createTime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });


            //
            $(document).on('click','.btn-spec_oper_btn', function () {
                var url = $(this).attr('data-url');
                //var aid = $(this).attr('data-value');
                var msg = $(this).attr('data-title');
                if(!url) return false
                url = url +'?aid=1';
                Fast.api.open(url,msg);
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});